<html>
<head>
<TITLE>CSE5317 Note 2</TITLE>
<!-- Changed by: Leonidas Fegaras, 10-Mar-1999 -->
</head>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<center>
<H1>MIPS Example</H1>
</center>
<p>
<hr>
<p>
The <a href="factorial.s">factorial.s</a> MIPS program implements the
following C++ program:
<pre>
int fact ( int n ) {
  if (n<=1) return 1;
  else return n*fact(n-1);
};

main () {
  int i, res;
  while (true) {
     cout << " Number? ";
     cin >> i;
     if (i<=0) break;
     res = fact(i);
     cout << "The factorial is: " << res << endl;
  };
};
</pre>
<p>
To run the factorial program on gamma, type
<tt>/public/cse/5317-501/spim/spim</tt>
and then (inside spim) type
<tt>load "/public/cse/5317-501/factorial.s"</tt>
and then <tt>run</tt>. (If you are using omega, use 4305 instead of 5317.)
<p>
<hr>
<P>
<ADDRESS>Last modified: 1/15/98 by <A HREF="http://www-cse.uta.edu/~fegaras/fegaras.html">Leonidas Fegaras</A></ADDRESS>
